define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'litestore_request/index' + location.search,
                    add_url: 'litestore_request/add',
                    edit_url: 'litestore_request/edit',
                    del_url: 'litestore_request/del',
                    multi_url: 'litestore_request/multi',
                    table: 'litestore_request',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showToggle:false,      
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'title', title: __('标题')},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'info_type', title: __('Info_type'), searchList: {"1":__('Info_type 1'),"2":__('Info_type 2'),"3":__('Info_type 3'),"4":__('Info_type 4'),"5":__('Info_type 5')}, formatter: Table.api.formatter.normal},
                        {field: 'req_contents', title: __('Req_contents'),formatter:function(value,row,index){
                            value=value?value:'';
                            var lg = value.length;
                            if(lg && lg>10)
                            {
                                return value.substring(0,10)+'....';
                            }
                            else{
                                return value;
                            }
                        }},
                        {field: 'price', title: __('Price')},
                        {field: 'trans_addr', title: __('Trans_addr')},
                        {field: 'publish_time', title: __('Publish_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},

                        {field: 'operate', title: __('Operate'),
                        table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});